#pragma once

#ifndef SPATIAL_SEARCHING_H_
#define SPATIAL_SEARCHING_H_

#include "stdafx.h"

#include <osg/Geode>
#include <osg/Geometry>
#include <osg/Shape>
#include <osg/NodeVisitor>

#include <CGAL/Cartesian.h>
#include <CGAL/Kd_tree.h>
#include <CGAL/Fuzzy_iso_box.h>
#include <CGAL/Search_traits_3.h>

#include <vector>
#include <map>
//#include <list>

typedef std::vector<osg::Geometry*> GeometryList;
typedef std::vector<unsigned int>   IndexList;
typedef std::map<osg::Geometry*, IndexList*> GeometryWithIndexList;

void free_GeometryWithIndexList_instance_contens(GeometryWithIndexList &gwil);
void free_GeometryWithIndexList_instance_ptr(GeometryWithIndexList *(&gwil));

class SpatialSearching
{
public:
	static void Search(osg::Node            *node, 
		               const osg::Box       *bbox, 
					   const osg::Vec3Array *polylineVertices);
	static GeometryWithIndexList *RoughSearch(osg::Node *node, const osg::BoundingBox *bbox);
	static GeometryWithIndexList *AccurateSearch(GeometryWithIndexList *VertexPoints, const osg::Vec3Array *polylineVertices);
};

class GeometryExtractor : public osg::NodeVisitor
{
public:
	GeometryExtractor();

	void apply(osg::Geometry &geomtry);

	GeometryList geometrylist;
};

#endif